package com.springboot.shanhexin.dao;

import com.springboot.shanhexin.entity.scenic_spot;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component(value = "scenic_spotDao")
public interface scenic_spotDao {

    //景区：scenic_spot

    /**
     * 显示总数量
     * @return
     */
    @Select("select count(*) from scenic_spot")
    int getCount();

    /**
     * 全部分页显示
     * @return
     */
    @Select("select a.* from scenic_spot a limit #{pos},#{size}")
    List<scenic_spot> findByPage(@Param("pos")int pos, @Param("size")int size);

    /**
     * 显示搜索的总数量
     * @return
     */
    @Select("select count(*) from scenic_spot a where a.name like concat(concat('%',#{name}),'%')")
    int getsearchCount(@Param("name")String name);

    /**
     * 搜索并分页显示
     * @return
     */
    @Select("select a.* from scenic_spot a where a.name like concat(concat('%',#{name}),'%') limit #{pos},#{size}")
    List<scenic_spot> findsearchByPage(@Param("name")String name,@Param("pos")int pos, @Param("size")int size);

    /**
     * 新增
     */
    @Insert("insert into scenic_spot(name) values(#{name})")
    void add(scenic_spot scenic_spot);

    /**
     * 删除
     */
    @Delete("delete from scenic_spot where id=#{id}")
    void delete(@Param("id")int id);

    /**
     * 修改(先找到并显示，再修改)
     */
    @Select("select a.* from scenic_spot a where a.id=#{id}")
    List<scenic_spot> getUserone(@Param("id")int id);

    @Update("update scenic_spot set name=#{name} where id=#{id}")
    void update(scenic_spot scenic_spot);

}
